package com.example.batchdemo.service.impl;

import com.example.batchdemo.model.BulkAdjustment;
import com.example.batchdemo.service.BulkAdjustmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @Author jason.tang
 * @Date 2019-10-07 09:21
 * @Desc
 */

@Slf4j
@Service("bulkAdjustmentService")
public class BulkAdjustmentServiceImpl implements BulkAdjustmentService {

    @Autowired
    @Qualifier("bulkAdjUserService")
    private BulkAdjustmentService bulkAdjustmentUserService;

    @Autowired
    @Qualifier("bulkAdjOrderService")
    private BulkAdjustmentService bulkAdjustmentOrderService;

    @Override
    public BulkAdjustment uploadDataFile(byte[] fileBytes, String fileType, String fileName) throws Exception {
        BulkAdjustment bulkAdjustment = null;

        if (BULK_ADJ_FILE_TYPE_USER.equals(fileType)) {
            bulkAdjustment = bulkAdjustmentUserService.uploadDataFile(fileBytes, fileType, fileName);

        } else if (BULK_ADJ_FILE_TYPE_ORDER.equals(fileType)) {
            bulkAdjustment = bulkAdjustmentOrderService.uploadDataFile(fileBytes, fileType, fileName);

        } else {
            throw new RuntimeException("Error");
        }
        return bulkAdjustment;
    }

    @Override
    public BulkAdjustment submitBulkAdjData(BulkAdjustment bulkAdjustment) {
        String fileType = bulkAdjustment.getFileType();

        if (BULK_ADJ_FILE_TYPE_USER.equals(fileType)) {
            bulkAdjustment = bulkAdjustmentUserService.submitBulkAdjData(bulkAdjustment);

        } else if (BULK_ADJ_FILE_TYPE_ORDER.equals(fileType)) {
            bulkAdjustment = bulkAdjustmentOrderService.submitBulkAdjData(bulkAdjustment);

        } else {
            throw new RuntimeException("Error");
        }
        return bulkAdjustment;
    }
}
